unit NetDiskUnit;

interface

uses
  Windows;

const
  WtVDiskDLL = 'WTVHD.dll';
  WtVDiskClientDll = 'WTNetDisk.dll';
  WtVDiskSys = 'filedisk.sys';

type
  PSERVER_PARAM = ^SERVER_PARAM;
  SERVER_PARAM = record
    dwRetry: DWORD;
    dwListenPort: DWORD;
    pServerTempPath: PChar;
    dwHandleThread: DWORD;
    dwCacheSize: DWORD;
  end;

  PCLIENT_PARAM = ^CLIENT_PARAM;
  CLIENT_PARAM = record
    pServerIp: PChar;
    ListenPort: DWORD;
    serverdrive: Char;
    clientdrive: Char;
    dwusemyLocalDiskEnableReadCache: DWORD;
    dwReadBufferSize: DWORD;
    dwWriteBufferSize: DWORD;
    dwusemyNolocalDisk: DWORD;
    dwnousemyNonDiskCacheSize: DWORD;
    dwNetTimeOut: DWORD;
    dwNetRetryTimes: DWORD;
    pusemyLocalDiskLocalTmpFolder: PChar;
    dwNetBulkCopySize: DWORD;
    dwMaxPreReadMiss: DWORD;
  end;

  StartServer = procedure(param: PSERVER_PARAM); stdcall;
  StopServer = procedure; stdcall;
  UpdateDisk = procedure(cdisk: Char); stdcall;

  InitNetDisk = procedure; stdcall;
  ExitNetDisk = procedure; stdcall;
  NetDiskMount = procedure(param: PCLIENT_PARAM); stdcall;
  NetDiskUmount = procedure(ClientDrive: Char); stdcall;

var
  fStartServer: StartServer;
  fStopServer: StopServer;
  fUpdateDisk: UpdateDisk;
  gServerDll: THandle;
  gClientDll: THandle;
  fInitNetDisk: InitNetDisk;
  fExitNetDisk: ExitNetDisk;
  fNetDiskMount: NetDiskMount;
  fNetDiskUmount: NetDiskUmount;

  procedure LoadServerLibs;
  procedure FreeServerLibs;

  procedure LoadClientLibs;
  procedure FreeClientLibs;
  
implementation

procedure LoadServerLibs;
begin
  gServerDll := LoadLibrary(WtVDiskDLL);
  fStartServer := GetProcAddress(gServerDll, 'StartServer');
  fStopServer := GetProcAddress(gServerDll, 'StopServer');
  fUpdateDisk := GetProcAddress(gServerDll, 'UpdateServer');
end;

procedure FreeServerLibs;
begin
  FreeLibrary(gServerDll);
end;


procedure LoadClientLibs;
begin
  gClientDll := LoadLibrary(WtVDiskClientDll);
  fInitNetDisk := GetProcAddress(gClientDll, 'InitNetDisk');
  fExitNetDisk := GetProcAddress(gClientDll, 'ExitNetDisk');
  fNetDiskMount := GetProcAddress(gClientDll, 'NetDiskMount');
  fNetDiskUmount := GetProcAddress(gClientDll, 'NetDiskUmount');
end;

procedure FreeClientLibs;
begin
  FreeLibrary(gClientDll);
end;

end.
